package com.googlecode.flair
{
	import com.googlecode.flair.editors.BaseEditor;
	
	import mx.events.ItemClickEvent;
	
	public class FlairApplication
	{
		
		public static var instance : FlairApplication = null;
		
		public var application : FlairApplicationView = null;
		private var designAdvisor : DesignAdvisor = null;
		
		public var rootComponent : IFlairComponent = null;
		
		public function FlairApplication()
		{
			instance = this;
		}
		
		
		public final function initializeApplication (application : FlairApplicationView) : void 
		{
			this.application = application;
			BaseEditor.componentDefinitions = this.application.flexComponents;
			BaseEditor.componentStyles = this.application.flexStyles;
			designAdvisor = new DesignAdvisor();
			var baseComponent : IFlairComponent = new FlairComponent(application.defaultView);
			
			FlairModelLocator.instance.rootComponent = baseComponent;
			FlairModelLocator.instance.currentComponent = baseComponent;
			designAdvisor.showFor(application, baseComponent);
		}
		
		public final function handleHeaderLinkClick(event : ItemClickEvent) : void {
			if (event.index < 2) {
				this.application.applicationViews.selectedIndex = event.index;
			}
		}

	}
}